package com.lianlianpay.util;

import java.net.URLEncoder;
import java.util.UUID;

import com.seek.util.ConstantsUtil;
import com.seek.util.HttpRequestUtils;
import com.seek.util.MD5Util;

import net.sf.json.JSONObject;

public class T {
    public static String getOrderIdByUUId() {
        int machineId = 3;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        // 0 代表前面补充0     
        // 4 代表长度为4     
        // d 代表参数为正数型吧
        return machineId + String.format("%013d", hashCodeV);
    }
    
    public static String getnoagreeIdByUUId() {
        int machineId = 3;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if(hashCodeV < 0) {//有可能是负数
            hashCodeV = - hashCodeV;
        }
        // 0 代表前面补充0     
        // 4 代表长度为4     
        // d 代表参数为正数型吧
        return machineId + String.format("%015d", hashCodeV);
    }
    
    
 public static String[] chars = new String[] { "a", "b", "c", "d", "e", "f",
            "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
            "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5",
            "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
            "W", "X", "Y", "Z" };


public static String generateShortUuid() {
    StringBuffer shortBuffer = new StringBuffer();
    String uuid = UUID.randomUUID().toString().replace("-", "");
    for (int i = 0; i < 8; i++) {
        String str = uuid.substring(i * 4, i * 4 + 4);
        int x = Integer.parseInt(str, 16);
        shortBuffer.append(chars[x % 0x3E]);
    }
    return shortBuffer.toString();
}

public static void main(String[] args) throws Exception {
	
	String reqStr = "{interId:'toa.submitCardBind',cardNo:6214835714400844,mobile:15257140162,companyId:1,ver:1000}";
//	String reqStr = "{interId:'toa.queryCardBind',ver:1000}";
//String reqStr = "{'acct_name':'路旭达','bank_code':'01050000','dt_order':'20170713140020','id_no':'410329199110263095','id_type':'0','info_order':'{\'companyId\':1,\'reqMoney\':30000,\'phone\':\'18986973950\',\'downMoney\':29937,\'repayId\':202,\'customerId\':\'6\'}','money_order':'0.1','no_agree':'2017071327554142','no_order':'202','oid_partner':'201408071000001543','oid_paybill':'2017071345606195','pay_type':'D','result_pay':'SUCCESS','settle_date':'20170713','sign':'A8zlejFi4IjahH5S/PxRTUbfaeQtQEaHHO6qTya4TxkJXNdRGxnQlR9Y3d2/e7enHJMWle9ADBl6H20EZfzwJ+CHC90Z8bJQxFy8f31GmjCQVEvX5w5vqlNC8TjtmSvNhwIOg08TLVJ5hnZoxadj4DjN71sD98+LQuESURDbIB4=','sign_type':'RSA'}";
//	System.out.println(JSONObject.fromObject(reqStr));
	String time = "1498873047";
	
	String token = "582b77b63ac74a5da43e4100f062d371";
	
	String signStr = "time" + time + "token" + token + reqStr + ConstantsUtil.SIGN_KEY;
	signStr = signStr.replaceAll(" ", "");
	signStr = signStr.replaceAll("\\*", "");
	signStr = URLEncoder.encode(signStr, "UTF-8");
	String currentSign = MD5Util.MD5(signStr).toLowerCase();
	
	String url = "http://localhost:8080/huajinbao/appservice?token="+token+"&time=1498873047&sign="+currentSign;
//	String url = "http://localhost:8080/huajinbao/tradepayapi/repayment";
	
	System.out.println(url);
	String res = HttpRequestUtils.httpPost(url,reqStr);
	System.out.println(res);
}

}
